#include <linux/module.h>
#include <asm/desc.h>

#include "exceptions.h"

#define info(...) printk("<1> info " __VA_ARGS__)


void int_info_header(void)
{
  info("%-10s%6s%9s%11s",
       "test",
       "int?",
       "int num",
       "err code?");
}

void int_info(char *name)
{
  info("%-10s%6s%9hu%11s",
       name,
       (last_int_info.interrupt ? "yes" : "no"),
       last_int_info.int_num,
       (last_int_info.has_error_code ? "yes" : "no"));
}



static int my_init(void)
{
    info("begin");

    init_exception_handling();
    
    EXCEPTIONS_BEGIN("DE");
    
    asm("xorl %ecx, %ecx\n\t"
        "divl %ecx\n\t");

    EXCEPTIONS_END("DE");
    
    int_info_header();
    int_info("DE");
    
    EXCEPTIONS_BEGIN("lmeGP");
    
    asm("movl $0xC0000080, %ecx\n\t"
        "rdmsr\n\t"
        "andl $(~(1<<8)), %eax\n\t"
        "wrmsr\n\t");

    EXCEPTIONS_END("lmeGP");
    
    int_info("lmeGP");

    EXCEPTIONS_BEGIN("int14");
    
    asm("int $14");

    EXCEPTIONS_END("int14");
    
    int_info("int14");
    
    EXCEPTIONS_BEGIN("int200");
    
    asm("int $200");

    EXCEPTIONS_END("int200");
    
    int_info("int200");
    
    EXCEPTIONS_BEGIN("mov");
    
    asm("movl %eax, %eax");

    EXCEPTIONS_END("mov");
    
    int_info("mov");
    
    info("finish");
    
    return 0;
}

static void my_exit(void) {
    info("exit");
}

module_init(my_init);
module_exit(my_exit);
